// pages/index/component/foundHead/foundHead.js
import { list } from '../../../../api/talent'
const util = require('../../../../utils/util')
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    swipersIndex: 0,
    length: 0,
    members: []
  },
  lifetimes: {
    attached() {
      this.loadTalent()


      this.setNavSize()
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    loadTalent() {
      list({
        pageSize: 20
      }).then(res => {

        let talents = res.data.data.length
        let lineNum = talents % 4 === 0 ? talents / 4 : Math.floor((talents / 4) + 1);
        for (let i = 0; i < lineNum; i++) {
          let temp = res.data.data.slice(i * 4, i * 4 + 4);

          this.data.members.push(temp)
        }
        // debugger
        this.data.members = this.data.members.map(e =>
          e.map(f => {
            return {
              ...f,
              avatar: util.thumbnail(f.avatar, 52, 52)
            }
          })
        )
        this.setData({
          members: this.data.members,
          length: this.data.members.length - 1
        })
      })
    },
    toSearch() {
      wx.navigateTo({
        url: '/pages/goods/search/index?id=5'
      })
    },
    toMember(e) {
      wx.navigateTo({
        url: '/pages/member/follow/dynamic/index?id=' + e.currentTarget.dataset.id
      })
    },
    bindChange(e) {
      this.setData({
        swipersIndex: e.detail.current
      })
      console.log(e.detail.current)
    },
    subtraction() {
      this.setData({
        swipersIndex: this.data.swipersIndex - 1
      })
    },
    addIndex() {
      this.setData({
        swipersIndex: this.data.swipersIndex + 1
      })
    },
    setNavSize: function () {
      var that = this,
        sysinfo = wx.getSystemInfoSync(),
        statusHeight = sysinfo.statusBarHeight,
        isiOS = sysinfo.system.indexOf('iOS') > -1,
        navHeight;
      console.log(sysinfo)
      if (!isiOS) {
        navHeight = 48;
      } else {
        navHeight = 44;
      }
      that.setData({
        status: statusHeight,
        navHeight: navHeight
      })
    },
    toPublish: function () {
      wx.navigateTo({
        url: '/pages/discovery/publish/publish',
      })
    }
  }
})
